package com.yx.cloud.view;

import android.content.Context;
import android.os.CountDownTimer;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.iot.common.utils.LogUtils;
import com.iot.product.sweeper.bean.AreaInfo;
import com.iot.product.sweeper.bean.CleanSettings;
import com.iot.product.sweeper.bean.Map;
import com.iot.product.sweeper.bean.Robot;
import com.iot.product.sweeper.bean.RobotStatus;
import com.iot.product.sweeper.bean.Room;
import com.iot.product.sweeper.config.SweeperProductConfig;
import com.iot.sweeper.AppContext;
import com.iot.sweeper.param.CleanParam;
import com.iot.sweeper.param.CleanSettingParam;
import com.yx.cloud.R;
import com.yx.cloud.activity.CustomModeActivity;
import com.yx.cloud.activity.MainActivity2;
import com.yx.cloud.activity.MapManagerActivity;
import com.yx.cloud.activity.RoomEditActivity;
import com.yx.cloud.adapter.RoomEditAdapter;
import com.yx.cloud.bean.CleanModeParam;
import com.yx.cloud.constant.Constants;
import com.yx.cloud.product.ProductConfigConstants;
import com.yx.cloud.utils.CommonConfirmDialog2;
import com.yx.cloud.utils.DisplayUtil;
import com.yx.cloud.utils.Intent_utils;
import com.yx.cloud.utils.RomUtils;
import com.yx.cloud.utils.SharedPrefsUtil;
import com.yx.cloud.utils.ToastUtil;


import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class BottomLayoutView extends LinearLayout implements
        RadioGroup.OnCheckedChangeListener, View.OnClickListener, View.OnLongClickListener {
    private final static String TAG = "BottomLayoutView";
    public Button mMainCleanMotionButton, mRbMainHouseClean, mRbMainChooseRoom, mRbMainSpotClean,
            mRbMainSweepAlongWall, mRbMainQuickCleaning;
    public TextView mMainCheckMap, mTvMainRecharge, mTvPreferences;
    public ImageView mIvMapManagerNotRead;
    public NestedScrollView mMainButtomScrollView;
    public RelativeLayout mRbPatternBar011, mRbPatternBar022, mRbPatternBar033, mRbPatternBar044, mRbPatternBar055,
            mRlBaseStationwateBar011, mRlBaseStationwateBar022,
            mRlBaseStationwateBar033, mRlBaseStationwateBar044;
    public LinearLayout mMainCleanType, mLlMainBottomBackwashFrequency, mRgMainPattern,
            mLlMainBottomBaseStationWater, mMainButtonLayout, ll_mainBottomSmartBlanket,
            mLlMainBottomSuction, ll_mainBottomAutoBlanket, ll_mainBottomCarpetSetting,
            ll_mainBottomCleanMode;
    public RadioButton mRbMainPattern011, mRbMainPattern022, mRbMainPattern033, mRbMainPattern044, mRbMainPattern055,
            mRbMainBackwashFrequency10, mRbMainBackwashFrequency20, mRbMainBackwashFrequency30, rb_SweepDragMode,
            rb_dragOnlyMode, rb_scanOnlyMode, mRbMainBaseStationWater02, mRbMainBaseStationWater03, mRbMainBaseStationWater04,
            rb_mainBottomRoomx1, rb_mainBottomRoomx2, mRbMainBaseStationWater01;
    public TimeCountWater bun_time_water;
    public TimeCountSuction bun_time_sucion;
    public TimeCountMode bun_time_mode;
    public CheckBox mCbMainBottomUnfold, mCbMainSupercharge, mCbMainFineRub, mCbMainCustomMade;
    public int mSuction, mWater;
    private MainActivity2 mainActivity;
    private RecyclerView mRlMainBottomRoomListView;
    private Robot robot;
    private RelativeLayout mRlMainBottomCustomMode, mRlMainBottomSterilizationMode, mLlMainBottomAutoBoost,
            mRlMainBottomWipingMode, mRlPatternOne, mRlMainWater011, mRlPatternThree, mRlPatternFour;
    private RadioGroup mRgMainBottomFrequency, mRgMainBottomBackwashFrequency, rg_mainBottomCleanMode, rg_BaseStation_waterLayout;
    private TextView mMainBottomRoomEdit, mMainBottomCustomizeEdit, tv_mainBottomSmartBlanket1, tv_mainBottomSmartBlanket2,
            tv_mainBottomAutoBlanket1, tv_mainBottomAutoBlanket2;
    private int workState, workMode, cleanMode = -1, suction_record = -1, water_record = -1;
    private boolean carpetPressurize_record = false, customSwitch_record = false;
    public String mStateMode = "";
    private List<Integer> mSelectdRoomIds;
    private RoomEditAdapter mRoomAdapter;
    private CleanModeParam cleanModeParam = new CleanModeParam();
    private CleanParam param = new CleanParam();

    public BottomLayoutView(Context context) {
        super(context);
    }

    public BottomLayoutView(Context context, AttributeSet attrs) {
        super(context, attrs);
        LogUtils.i(" : BottomLayoutView*************************** : ");
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.main_bottom_layout, this);
        mainActivity = (MainActivity2) context;
        initView(view);
        initData();
    }

    private void initView(View view) {

        mMainButtonLayout = view.findViewById(R.id.main_bottom);
        mCbMainBottomUnfold = view.findViewById(R.id.cb_mainUnfold);

        mRbMainHouseClean = view.findViewById(R.id.rb_mainHouseClean);
        mRbMainChooseRoom = view.findViewById(R.id.rb_mainChooseRoom);
        mRbMainSpotClean = view.findViewById(R.id.rb_mainSpotClean);
        mRbMainSweepAlongWall = view.findViewById(R.id.rb_mainSweepAlongWall);
        mRbMainQuickCleaning = view.findViewById(R.id.rb_mainQuickCleaning);

        mRlMainBottomCustomMode = view.findViewById(R.id.rl_mainBottomCustomMode);
        mRlMainBottomSterilizationMode = view.findViewById(R.id.rl_mainBottomSterilizationMode);
        mRlMainBottomWipingMode = view.findViewById(R.id.rl_mainBottomWipingMode);
        mRgMainBottomFrequency = view.findViewById(R.id.rg_mainBottomFrequency);
        mRgMainBottomBackwashFrequency = view.findViewById(R.id.main_radiogroup_BackwashFrequency);

        mRlMainBottomRoomListView = view.findViewById(R.id.main_bottom_roomList);
        mRoomAdapter = new RoomEditAdapter(mainActivity);
        mRlMainBottomRoomListView.setAdapter(mRoomAdapter);
        GridLayoutManager layoutManager = new GridLayoutManager(mainActivity, 3);
        mRlMainBottomRoomListView.setLayoutManager(layoutManager);

        mLlMainBottomBackwashFrequency = view.findViewById(R.id.ll_mainBottomBackwashFrequency);
        mLlMainBottomBaseStationWater = view.findViewById(R.id.ll_mainBottomBaseStationWater);
        mMainButtomScrollView = view.findViewById(R.id.mainButtomScrollView);
        mMainCleanType = view.findViewById(R.id.ll_cleanType);

        mRlPatternOne = view.findViewById(R.id.rl_patternOne);
        mRlPatternThree = view.findViewById(R.id.rl_patternThree);
        mRlPatternFour = view.findViewById(R.id.rl_patternFour);
        mRbMainPattern011 = view.findViewById(R.id.iv_main_pattern011);
        mRbMainPattern022 = view.findViewById(R.id.iv_main_pattern022);
        mRbMainPattern033 = view.findViewById(R.id.iv_main_pattern033);
        mRbMainPattern044 = view.findViewById(R.id.iv_main_pattern044);
        mRbMainPattern055 = view.findViewById(R.id.iv_main_pattern055);

        mRbPatternBar011 = view.findViewById(R.id.rl_patternBar011);
        mRbPatternBar022 = view.findViewById(R.id.rl_patternBar022);
        mRbPatternBar033 = view.findViewById(R.id.rl_patternBar033);
        mRbPatternBar044 = view.findViewById(R.id.rl_patternBar044);
        mRbPatternBar055 = view.findViewById(R.id.rl_patternBar055);

//        mRlMainWater011 = view.findViewById(R.id.rl_mainWater011);

        rg_BaseStation_waterLayout = view.findViewById(R.id.rg_BaseStation_waterLayout);
        mRbMainBaseStationWater01 = view.findViewById(R.id.iv_main_BaseStation_water01);
        mRbMainBaseStationWater02 = view.findViewById(R.id.iv_main_BaseStation_water02);
        mRbMainBaseStationWater03 = view.findViewById(R.id.iv_main_BaseStation_water03);
        mRbMainBaseStationWater04 = view.findViewById(R.id.iv_main_BaseStation_water04);

        mRbMainBackwashFrequency10 = view.findViewById(R.id.iv_main_BackwashFrequency10);
        mRbMainBackwashFrequency20 = view.findViewById(R.id.iv_main_BackwashFrequency20);
        mRbMainBackwashFrequency30 = view.findViewById(R.id.iv_main_BackwashFrequency30);

        mCbMainSupercharge = view.findViewById(R.id.cb_main_supercharge);
        mCbMainFineRub = view.findViewById(R.id.cb_main_fineRub);
        mCbMainCustomMade = view.findViewById(R.id.cb_customMade);
        mRgMainPattern = view.findViewById(R.id.main_radiogroup_pattern);
        mMainBottomRoomEdit = view.findViewById(R.id.main_bottom_roomEdit);
        mMainCleanMotionButton = view.findViewById(R.id.mainCleanMotionButton);
        mMainBottomCustomizeEdit = view.findViewById(R.id.main_bottom_customizeEdit);
        mMainCheckMap = view.findViewById(R.id.tv_checkMap);
        mTvPreferences = view.findViewById(R.id.tv_preferences);
        mLlMainBottomSuction = view.findViewById(R.id.ll_mainBottomSuction);
        mTvMainRecharge = view.findViewById(R.id.tv_mainRechargeState);
        mLlMainBottomAutoBoost = view.findViewById(R.id.ll_mainBottomAutoBoost);
        mIvMapManagerNotRead = view.findViewById(R.id.iv_map_manager_not_read);

//        mRlBaseStationwateBar011 = view.findViewById(R.id.rl_BaseStationwateBar011);
//        mRlBaseStationwateBar022 = view.findViewById(R.id.rl_BaseStationwateBar022);
//        mRlBaseStationwateBar033 = view.findViewById(R.id.rl_BaseStationwateBar033);
//        mRlBaseStationwateBar044 = view.findViewById(R.id.rl_BaseStationwateBar044);

        rb_mainBottomRoomx1 = view.findViewById(R.id.rb_mainBottomRoomx1);
        rb_mainBottomRoomx2 = view.findViewById(R.id.rb_mainBottomRoomx2);

        ll_mainBottomCarpetSetting = view.findViewById(R.id.ll_mainBottomCarpetSetting);
        ll_mainBottomSmartBlanket = view.findViewById(R.id.ll_mainBottomSmartBlanket);
        ll_mainBottomAutoBlanket = view.findViewById(R.id.ll_mainBottomAutoBlanket);
        tv_mainBottomSmartBlanket1 = view.findViewById(R.id.tv_mainBottomSmartBlanket1);
        tv_mainBottomSmartBlanket2 = view.findViewById(R.id.tv_mainBottomSmartBlanket2);
        tv_mainBottomAutoBlanket1 = view.findViewById(R.id.tv_mainBottomAutoBlanket1);
        tv_mainBottomAutoBlanket2 = view.findViewById(R.id.tv_mainBottomAutoBlanket2);

        ll_mainBottomCleanMode = view.findViewById(R.id.ll_mainBottom_CleanMode);
        rg_mainBottomCleanMode = view.findViewById(R.id.rg_mainBottomCleanMode);
        rb_SweepDragMode = view.findViewById(R.id.rb_SweepDragMode);
        rb_dragOnlyMode = view.findViewById(R.id.rb_dragOnlyMode);
        rb_scanOnlyMode = view.findViewById(R.id.rb_scanOnlyMode);


    }

    private void initData() {
        LogUtils.i(" : initData****33333*********************** : ");

        mRbMainPattern011.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                int suction = 0;
                robot = AppContext.get().getCurrentDevice();
                int mSuction = robot.getCleanSettings().getSuction();
                if (mSuction != suction) {
                    switchingSuction(suction);
                }
            }
        });
        mRbMainPattern022.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                int suction = 1;
                robot = AppContext.get().getCurrentDevice();
                int mSuction = robot.getCleanSettings().getSuction();
                if (mSuction != suction) {
                    switchingSuction(suction);
                }
            }
        });
        mRbMainPattern033.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                int suction = 2;
                robot = AppContext.get().getCurrentDevice();
                int mSuction = robot.getCleanSettings().getSuction();
                if (mSuction != suction) {
                    //如果已经是当前档位了，就不在响应指令下发
                    switchingSuction(suction);
                }
            }
        });
        mRbMainPattern044.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                int suction = 3;
                robot = AppContext.get().getCurrentDevice();
                int mSuction = robot.getCleanSettings().getSuction();
                if (mSuction != suction) {
                    switchingSuction(suction);
                }
            }
        });
        mRbMainPattern055.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                int suction = 4;
                robot = AppContext.get().getCurrentDevice();
                int mSuction = robot.getCleanSettings().getSuction();
                if (mSuction != suction) {
                    switchingSuction(suction);
                }
            }
        });

//        mRbMainBaseStationWater01.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (RomUtils.isFastClick()) {
//                    return;
//                }
//                int mopWater = 0;
//                robot = AppContext.get().getCurrentDevice();
//                int mopHumidity = robot.getCleanSettings().getMopHumidity();
//                if (mopHumidity != mopWater) {
//                    //如果已经是当前档位了，就不在响应指令下发
//                    switchWater(mopWater);
//                } else {
//                    LogUtils.i("基站1 : 点击 " + mopHumidity);
//                }
//            }
//        });
//        mRbMainBaseStationWater02.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (RomUtils.isFastClick()) {
//                    return;
//                }
//                int mopWater = 1;
//                robot = AppContext.get().getCurrentDevice();
//                int mopHumidity = robot.getCleanSettings().getMopHumidity();
//                if (mopHumidity != mopWater) {
//                    switchWater(mopWater);
//                } else {
//                    LogUtils.i("基站2 : 点击 " + mopHumidity);
//                }
//            }
//        });
//        mRbMainBaseStationWater03.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (RomUtils.isFastClick()) {
//                    return;
//                }
//                //禁止点击
//                int mopWater = 2;
//                robot = AppContext.get().getCurrentDevice();
//                int mopHumidity = robot.getCleanSettings().getMopHumidity();
//                if (mopHumidity != mopWater) {
//                    switchWater(mopWater);
//                } else {
//                    LogUtils.i("基站3 : 点击 " + mopHumidity);
//                }
//            }
//        });
//        mRbMainBaseStationWater04.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (RomUtils.isFastClick()) {
//                    return;
//                }
//                //禁止点击
//                int mopWater = 3;
//                robot = AppContext.get().getCurrentDevice();
//                int mopHumidity = robot.getCleanSettings().getMopHumidity();
//                if (mopHumidity != mopWater) {
//                    switchWater(mopWater);
//                } else {
//                    LogUtils.i("基站4 : 点击  " + mopHumidity);
//                }
//            }
//        });


        mRgMainPattern.setOnClickListener(this);
        mRgMainBottomBackwashFrequency.setOnCheckedChangeListener(this);
        mRgMainBottomFrequency.setOnCheckedChangeListener(this);
        rg_mainBottomCleanMode.setOnCheckedChangeListener(this);
        rg_BaseStation_waterLayout.setOnCheckedChangeListener(this);

        mMainBottomRoomEdit.setOnClickListener(this);
        mMainBottomCustomizeEdit.setOnClickListener(this);
        //清扫按钮长按
        mMainCleanMotionButton.setOnLongClickListener(this);
        mMainCleanMotionButton.setOnClickListener(this);
        //回充按钮长按
        mTvMainRecharge.setOnLongClickListener(this);
        mTvMainRecharge.setOnClickListener(this);
        mMainCheckMap.setOnClickListener(this);
        mTvPreferences.setOnClickListener(this);
        mRbMainHouseClean.setOnClickListener(this);
        mRbMainChooseRoom.setOnClickListener(this);
        mRbMainSpotClean.setOnClickListener(this);
        mRbMainSweepAlongWall.setOnClickListener(this);
        ll_mainBottomSmartBlanket.setOnClickListener(this);
        ll_mainBottomAutoBlanket.setOnClickListener(this);

        mCbMainCustomMade.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (buttonView.isPressed()) {
                    //定制模式开关
                    LogUtils.i("定制模式开关 : " + isChecked);
                    AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().customSwitch(isChecked).build());
                }
            }
        });
        mCbMainFineRub.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (buttonView.isPressed()) {
                    //精擦模式
                    LogUtils.i("精擦模式 : " + isChecked);
                    AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().fineBrush(isChecked).build());
                }

            }
        });
        mCbMainSupercharge.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (buttonView.isPressed()) {
                    //地毯增压
//                Log.d(TAG, "地毯增压 : " + isChecked);
                    AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().carpetPressurize(isChecked).build());
                }
            }
        });
        mSelectdRoomIds = new ArrayList<>();
    }

    @Override
    public boolean onLongClick(View v) {
        robot = AppContext.get().getCurrentDevice();
        workState = robot.getRobotStatus().getWorkState();
        workMode = robot.getRobotStatus().getWorkMode();
        int id = v.getId();
        if (id == R.id.mainCleanMotionButton) {
            if ((workState == RobotStatus.STATE_WORKING || workState == RobotStatus.STATE_PAUSE) && workMode != RobotStatus.MODE_RECHARGE) {
                //清扫按钮长按
                showLongClickDialog("是否结束清扫", 1);
            }
        } else if (id == R.id.tv_mainRechargeState) {
            LogUtils.i(workMode + " : 长按回充****jjjjjjjjjjjjjjj*********************** : " + workState);
            if ((workState == RobotStatus.STATE_WORKING || workState == RobotStatus.STATE_PAUSE)
                    && workMode == RobotStatus.MODE_RECHARGE) {
//                    Log.d(TAG, " : 长按回充****33333*********************** : ");
                //回充按钮长按
                showLongClickDialog("是否结束回充", 2);
            }
        }
        return true;
    }

    /**
     * 编辑
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        int id = v.getId();
        if (id == R.id.main_bottom_roomEdit) {
            //房间编辑
            //  AppContext.get().setDeviceVariety("map");
            Intent_utils.enterIntent(mainActivity, RoomEditActivity.class);
        } else if (id == R.id.main_bottom_customizeEdit) {
            //定制编辑
            //   AppContext.get().setDeviceVariety("map");
            Intent_utils.enterIntent(mainActivity, CustomModeActivity.class);
        }
        if (id == R.id.tv_preferences) {
            //偏好设置
            if (Constants.isButtomOpen) {
                mainActivity.setBottomUiState("close", true, "160");
                mainActivity.mainFragment.bottomLayoutView.mCbMainBottomUnfold.setChecked(false);
            } else {
                mainActivity.setBottomUiState("open", false, "open 333");
                mainActivity.mainFragment.bottomLayoutView.mCbMainBottomUnfold.setChecked(true);
            }
        } else if (id == R.id.tv_checkMap) {
            //地图管理 查看地图
            SharedPrefsUtil.putValue(mainActivity, Constants.NOT_READ_TAG, Constants.KEY_MAP_MANAGER_NOT_READ, false);
            Intent_utils.enterIntentResult(mainActivity, MapManagerActivity.class, "map");

        } else if (id == R.id.tv_mainRechargeState) {
            //回充指令发送/集尘
            JSONObject config = AppContext.getConfig();
            if (config.optBoolean(ProductConfigConstants.rechargeBaseStation)) {
                BottomBaseStationDialogLayout fragment = new BottomBaseStationDialogLayout();
                fragment.show(mainActivity.getSupportFragmentManager(), "ssss");
            } else {
                String text = mTvMainRecharge.getText().toString().trim();
                if (text.equals(mainActivity.getString(R.string.Finished_collecting_dust))) {
                    //立即集尘
                    AppContext.getProductService().collectDust();
                } else {
                    robot = AppContext.get().getCurrentDevice();
                    if (robot == null) {
                        LogUtils.i("回充*************************** get robot is null ");
                        return;
                    }
                    workState = robot.getRobotStatus().getWorkState();
                    workMode = robot.getRobotStatus().getWorkMode();
                    LogUtils.i("回充***************************  " + workState + " , " + workMode);
                    if (workState == RobotStatus.STATE_WORKING && workMode == RobotStatus.MODE_RECHARGE) {
                        robot.pauseRecharge();
                    } else if (workState == RobotStatus.STATE_PAUSE && workMode == RobotStatus.MODE_RECHARGE) {
                        robot.continueRecharge();
                    } else {
                        robot.startRecharge();
                    }
                }
                clearSelectRoom();
            }
            mainActivity.setBottomUiState("close", true, "回充");
        } else if (id == R.id.mainCleanMotionButton) {
            //Log.d(TAG, " : 清扫指令发送****33333*********************** : ");
            //清扫指令发送
            boolean roomTag = false;
            robot = AppContext.get().getCurrentDevice();
            if (robot == null) {
                LogUtils.i("清扫指令发送*************************** get robot is null ");
                return;
            }
            workState = robot.getRobotStatus().getWorkState();
            workMode = robot.getRobotStatus().getWorkMode();
            LogUtils.i(workState + " : 清扫指令发送****4444444*********************** : " + workMode);
            if (workState == RobotStatus.STATE_DUST_COLLECTION) {
                ToastUtil.show(mainActivity, mainActivity.getResources().getString(R.string.Collect_ing), Toast.LENGTH_LONG);
                return;
            }
            if (workState == RobotStatus.STATE_WORKING) {
                if (workMode == RobotStatus.MODE_RECHARGE) {
                    //如果此时是回充中
                    if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                        cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
                    }
                    param.setType(cleanModeParam.getType());
                    AppContext.getProductService().startSweep(param);
                } else {
                    //当前是清扫，应发送暂停
                    AppContext.getProductService().pauseSweep();
                }
            } else if (workState == RobotStatus.STATE_PAUSE) {
                //这里暂停（回充模式 遥控模式）
                if (workMode == RobotStatus.MODE_RECHARGE || workMode == RobotStatus.MODE_CONTROL) {
                    //当前回充模式，要发开始清扫
                    if (cleanModeParam.getType() == RobotStatus.MODE_AUTO_CLEAN) {
                        //自动清扫
                        cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
                    } else if (cleanModeParam.getType() == RobotStatus.MODE_ROOM_CLEAN) {
                        //选区清扫
                        List<Integer> roomIds = mRoomAdapter.getSelectRoom();
                        List<Room> mapRoomList = AppContext.get().getCurrentDevice().getMap().getRoom();
                        List<Room> seletecdRoomList = new ArrayList<>();
                        for (int roomId : roomIds) {
                            for (int i = 0; i < mapRoomList.size(); i++) {
                                if (roomId == mapRoomList.get(i).getId()) {
                                    seletecdRoomList.add(mapRoomList.get(i));
                                    break;
                                }
                            }
                        }
                        if (seletecdRoomList.size() > 0) {
                            List<CleanParam.SweepParam> paramList = new ArrayList<>();
                            for (Room room : seletecdRoomList) {
                                CleanParam.RoomSweepParam param1 = new CleanParam.RoomSweepParam();
                                param1.setRoom(room);
                                CleanSettings cleanSettings = new CleanSettings();
                                cleanSettings.setCleanTimes(robot.getSetTemporaryPara().getRoomFrequency());
                                param1.setCleanSettings(cleanSettings);
                                paramList.add(param1);
                            }
                            cleanModeParam.setType(RobotStatus.MODE_ROOM_CLEAN);
                            cleanModeParam.setSweepParamList(paramList);
                            param.setSweepParamList(paramList);
                        } else {
                            //如果没有房间
                            ToastUtil.show(mainActivity, mainActivity.getString(R.string.MM_T_SelectRoom), Toast.LENGTH_SHORT);
                            return;
                        }
                    } else if (cleanModeParam.getType() == RobotStatus.MODE_SPOT_CLEAN) {
                        //局部清扫 如果选中局部模式 直接开始
                        cleanModeParam.setType(RobotStatus.MODE_SPOT_CLEAN);
                    } else if (cleanModeParam.getType() == RobotStatus.MODE_EDGE_CLEAN) {
                        //沿墙
                        cleanModeParam.setType(RobotStatus.MODE_EDGE_CLEAN);
                    } else {
                        // 默认 发送 自动清扫
                        cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
                    }
                    param.setType(cleanModeParam.getType());
                    AppContext.getProductService().startSweep(param);
                } else {
                    if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                        LogUtils.i(" : 清扫指令发送****开始继续*********************** : ");
                        List<AreaInfo> areaInfos = AppContext.get().getCurrentDevice().getMap().getArea();
                        List<CleanParam.SweepParam> paramList = new ArrayList<>();
                        for (AreaInfo areaInfo : areaInfos) {
                            if (areaInfo.getType() == AreaInfo.TYPE_CLEAN) {
                                CleanParam.AreaSweepParam param1 = new CleanParam.AreaSweepParam();
                                param1.setArea(areaInfo);
                                paramList.add(param1);
                            }
                        }
                        param.setType(workMode);
                        param.setSweepParamList(paramList);
                        AppContext.getProductService().continueSweep(param);
                    } else {
                        param.setType(cleanModeParam.getType());
                        AppContext.getProductService().startSweep(param);
                    }
                }
            } else {
                LogUtils.i(" : 清扫指令发送****5555555555555555*********************** : " + cleanModeParam.getType());
                //当前是停止或者是其他模式，发送开始
                if (cleanModeParam.getType() == RobotStatus.MODE_AUTO_CLEAN) {
                    //自动清扫
                    cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
                } else if (cleanModeParam.getType() == RobotStatus.MODE_ROOM_CLEAN) {
                    //选区清扫
                    LogUtils.i(" : 选区清扫****5555555555555555*********************** : ");
                    List<Integer> roomIds = mRoomAdapter.getSelectRoom();
                    List<Room> mapRoomList = AppContext.get().getCurrentDevice().getMap().getRoom();
                    List<Room> seletecdRoomList = new ArrayList<>();
                    for (int roomId : roomIds) {
                        for (int i = 0; i < mapRoomList.size(); i++) {
                            if (roomId == mapRoomList.get(i).getId()) {
                                seletecdRoomList.add(mapRoomList.get(i));
                                break;
                            }
                        }
                    }
                    if (seletecdRoomList.size() > 0) {
                        List<CleanParam.SweepParam> paramList = new ArrayList<>();
                        for (Room room : seletecdRoomList) {
                            CleanParam.RoomSweepParam param1 = new CleanParam.RoomSweepParam();
                            param1.setRoom(room);
                            CleanSettings cleanSettings = new CleanSettings();
                            cleanSettings.setCleanTimes(robot.getSetTemporaryPara().getRoomFrequency());
                            param1.setCleanSettings(cleanSettings);
                            paramList.add(param1);
                        }
                        cleanModeParam.setType(RobotStatus.MODE_ROOM_CLEAN);
                        cleanModeParam.setSweepParamList(paramList);
                        param.setSweepParamList(paramList);
                    } else {
                        //如果没有房间
                        ToastUtil.show(mainActivity, mainActivity.getString(R.string.MM_T_SelectRoom), Toast.LENGTH_SHORT);
                        return;
                    }
                } else if (cleanModeParam.getType() == RobotStatus.MODE_SPOT_CLEAN) {
                    LogUtils.i(" : 清扫指令发送****888888888888888888*********************** : ");
                    //局部清扫 如果选中局部模式 直接开始
                    cleanModeParam.setType(RobotStatus.MODE_SPOT_CLEAN);
                    if (workState == RobotStatus.STATE_CHARGING) {
                        ToastUtil.show(mainActivity, mainActivity.getString(R.string.U_Part_Cleaning_Tip), Toast.LENGTH_SHORT);
                        return;
                    }
                } else if (cleanModeParam.getType() == RobotStatus.MODE_EDGE_CLEAN) {
                    //沿墙
                    cleanModeParam.setType(RobotStatus.MODE_EDGE_CLEAN);
                } else {
                    LogUtils.i(" : 清扫指令发送****99999999999999999999999*********************** : ");
                    // 默认 发送 自动清扫
                    cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
                }
                param.setType(cleanModeParam.getType());
                AppContext.getProductService().startSweep(param);
            }
            clearSelectRoom();
            mainActivity.setBottomUiState("close", true, "清扫");
        } else if (id == R.id.rb_mainHouseClean) {
            //全局清扫
            robot = AppContext.get().getCurrentDevice();
            robot.getSetTemporaryPara().setSelectMode(1);//设置选择工作模式
            if (robot == null) {
                LogUtils.i("全局清扫*************************** get robot is null ");
                return;
            }
            workState = robot.getRobotStatus().getWorkState();
            workMode = robot.getRobotStatus().getWorkMode();
            mStateMode = "houseClean";
            LogUtils.i(workMode + " : 选择 全局清扫****33333*********************** : " + workState);
            if ((workState == RobotStatus.STATE_WORKING || workState == RobotStatus.STATE_PAUSE) && workMode != RobotStatus.MODE_RECHARGE) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    currentTaskDialog(mainActivity.getString(R.string.H_EndTask), mStateMode);
                } else {
                    cleanModeBgShow01();
                    changeTab(mStateMode);
                }
            } else if (workMode == RobotStatus.MODE_RECHARGE && workState == RobotStatus.STATE_WORKING) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    AppContext.getProductService().pauseRecharge();
                }
                cleanModeBgShow01();
            } else {
                cleanModeBgShow01();
            }
            mMainCleanType.setVisibility(View.GONE);
            cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
            cleanModeCheck01();
            clearSelectRoom();
        } else if (id == R.id.rb_mainChooseRoom) {
            //选区清扫
            LogUtils.i(" :选择 选区清扫****33333*********************** : ");
            robot = AppContext.get().getCurrentDevice();
            robot.getSetTemporaryPara().setSelectMode(2);//设置选择工作模式
            if (robot == null) {
                LogUtils.i("选区清扫*************************** get robot is null ");
                return;
            }
            List<Room> mapRoomList = getCopyRooms();
            if (mapRoomList.size() == 0) {
                ToastUtil.show(mainActivity, mainActivity.getString(R.string.MM_Room_NoContent), Toast.LENGTH_SHORT);
                return;
            }
            workState = robot.getRobotStatus().getWorkState();
            workMode = robot.getRobotStatus().getWorkMode();
            mStateMode = "chooseRoom";
            LogUtils.i(workMode + " : 选区清扫****33333*********************** : " + workState);
            if ((workState == RobotStatus.STATE_WORKING || workState == RobotStatus.STATE_PAUSE) && workMode != RobotStatus.MODE_RECHARGE) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    currentTaskDialog(mainActivity.getString(R.string.H_EndTask), mStateMode);
                } else {
                    cleanModeBgShow02();
                    changeTab(mStateMode);
                }
            } else if (workMode == RobotStatus.MODE_RECHARGE && workState == RobotStatus.STATE_WORKING) {
                LogUtils.i(" :选择 选区清扫****ggggggg*********************** : ");
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    AppContext.getProductService().pauseRecharge();
                }
                cleanModeBgShow02();
            } else {
                if (mapRoomList.size() > 0) {
                    mRoomAdapter.updateData(mapRoomList, mSelectdRoomIds);
                    mMainCleanType.setVisibility(View.VISIBLE);
                    cleanModeBgShow02();
                }
            }
            cleanModeParam.setType(RobotStatus.MODE_ROOM_CLEAN);
            cleanModeCheck02();
        } else if (id == R.id.rb_mainSpotClean) {
            //局部清扫
            robot = AppContext.get().getCurrentDevice();
            robot.getSetTemporaryPara().setSelectMode(3);//设置选择工作模式
            if (robot == null) {
                LogUtils.i("局部清扫*************************** get robot is null ");
                return;
            }
            workState = robot.getRobotStatus().getWorkState();
            workMode = robot.getRobotStatus().getWorkMode();
            mStateMode = "spotClean";
            LogUtils.i(workMode + " : 局部清扫****33333*********************** : " + workState);
            if ((workState == RobotStatus.STATE_WORKING || workState == RobotStatus.STATE_PAUSE) && workMode != RobotStatus.MODE_RECHARGE) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    currentTaskDialog(mainActivity.getString(R.string.H_EndTask), mStateMode);
                } else {
                    cleanModeBgShow03();
                    changeTab(mStateMode);
                }
            } else if (workMode == RobotStatus.MODE_RECHARGE && workState == RobotStatus.STATE_WORKING) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    AppContext.getProductService().pauseRecharge();
                }
                cleanModeBgShow03();
            } else {
                cleanModeBgShow03();
            }
            mMainCleanType.setVisibility(View.GONE);
            cleanModeParam.setType(RobotStatus.MODE_SPOT_CLEAN);
            cleanModeCheck03();
            LogUtils.i("局部清扫");
            clearSelectRoom();
        } else if (id == R.id.rb_mainSweepAlongWall) {
            //沿墙清扫
            mStateMode = "sweepAlongWall";
            robot = AppContext.get().getCurrentDevice();
            robot.getSetTemporaryPara().setSelectMode(4);//设置选择工作模式
            if ((workState == RobotStatus.STATE_WORKING || workState == RobotStatus.STATE_PAUSE) && workMode != RobotStatus.MODE_RECHARGE) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    currentTaskDialog(mainActivity.getString(R.string.H_EndTask), mStateMode);
                } else {
                    cleanModeBgShow04();
                    changeTab(mStateMode);
                }
            } else if (workMode == RobotStatus.MODE_RECHARGE && workState == RobotStatus.STATE_WORKING) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    AppContext.getProductService().pauseRecharge();
                }
                cleanModeBgShow04();
            } else {
                cleanModeBgShow04();
            }
            mMainCleanType.setVisibility(View.GONE);
            cleanModeParam.setType(RobotStatus.MODE_EDGE_CLEAN);
            cleanModeCheck04();
            LogUtils.i("沿墙清扫");
            clearSelectRoom();
        } else if (id == R.id.rb_mainQuickCleaning) {
            //快速清扫
            mStateMode = "quickClean";
            robot = AppContext.get().getCurrentDevice();
            robot.getSetTemporaryPara().setSelectMode(5);//设置选择工作模式
            if ((workState == RobotStatus.STATE_WORKING || workState == RobotStatus.STATE_PAUSE) && workMode != RobotStatus.MODE_RECHARGE) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    currentTaskDialog(mainActivity.getString(R.string.H_EndTask), mStateMode);
                } else {
                    cleanModeBgShow05();
                    changeTab(mStateMode);
                }
            } else if (workMode == RobotStatus.MODE_RECHARGE && workState == RobotStatus.STATE_WORKING) {
                if (robot.getConfig().optInt(ProductConfigConstants.product_type) != ProductConfigConstants.PRODUCT_TYPE_GYRO) {
                    AppContext.getProductService().pauseRecharge();
                }
                cleanModeBgShow05();
            } else {
                cleanModeBgShow05();
            }
            mMainCleanType.setVisibility(View.GONE);
            cleanModeParam.setType(RobotStatus.MODE_EDGE_CLEAN);
            cleanModeCheck05();
            clearSelectRoom();
        } else if (id == R.id.ll_mainBottomSmartBlanket) {
            //智能上毯
            AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().setCarpetSetting(0).build());
            smartBlanket();
        } else if (id == R.id.ll_mainBottomAutoBlanket) {
            //自动避毯
            if (robot.getCameraSettings().isOnCarpet()) {
                ToastUtil.show(mainActivity, mainActivity.getString(R.string.T_Device_carpet_needRemove), Toast.LENGTH_SHORT);
                return;
            }
            AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().setCarpetSetting(1).build());
            autoBlanket();
        }
    }

    private void currentTaskDialog(String content, String type) {
        CommonConfirmDialog2.newBuilder()
                .context(mainActivity)
                .message(content)
                .confirmCallback(new CommonConfirmDialog2.ConfirmCallback() {
                    @Override
                    public boolean onConfirm() {
                        Constants.bun_time_mode = true;
                        if (bun_time_mode == null) {
                            //点击吸力水量 开始倒计时
                            bun_time_mode = new TimeCountMode(2000, 1000);
                        }
                        bun_time_mode.start();
                        //结束清扫 houseClean
                        AppContext.getProductService().stopSweep();

                        changeTab(type);
                        return true;
                    }

                    @Override
                    public boolean onCancel() {
                        robot = AppContext.get().getCurrentDevice();
                        robot.getSetTemporaryPara().setSelectMode(0);//设置选择工作模式
                        return true;
                    }
                }).build().show();
    }

    private void changeTab(String type) {
        if (type.equals("houseClean")) {
            //全局
            cleanModeBgShow01();
            cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
            mMainCleanType.setVisibility(View.GONE);
        } else if (type.equals("chooseRoom")) {
            //选区
            List<Room> mRoomList = getCopyRooms();
            if (mRoomList.size() > 0) {
                if (mRoomAdapter != null) {
                    mRoomAdapter.updateData(mRoomList, mSelectdRoomIds);
                    cleanModeParam.setType(RobotStatus.MODE_ROOM_CLEAN);
                    mMainCleanType.setVisibility(View.VISIBLE);
                    //   Log.d(TAG, "选区清扫****获取房间分区*********************** : " + AppContext.get().param.getType());
                    cleanModeBgShow02();
                }

            }

        } else if (type.equals("spotClean")) {
            //局部
            mMainCleanType.setVisibility(View.GONE);
            cleanModeParam.setType(RobotStatus.MODE_SPOT_CLEAN);
            cleanModeBgShow03();
        } else if (type.equals("sweepAlongWall")) {
            //沿墙
            mMainCleanType.setVisibility(View.GONE);
            cleanModeParam.setType(RobotStatus.MODE_EDGE_CLEAN);
            cleanModeBgShow04();
        } else if (type.equals("quickClean")) {
            //快速
            mMainCleanType.setVisibility(View.GONE);
            cleanModeParam.setType(RobotStatus.MODE_EDGE_CLEAN);
            cleanModeBgShow05();
        }
    }

    public void refreshRoom() {
        Robot robot = AppContext.get().getCurrentDevice();
        if (robot == null) {
            return;
        }
        List<Room> mapRoomList = getCopyRooms();
        if (mapRoomList.size() > 0) {
            roomSelect();
            mRoomAdapter.updateData(mapRoomList, mSelectdRoomIds);
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        int id = group.getId();
        if (id == R.id.main_radiogroup_BackwashFrequency) {
            //回洗频率
            setBackwashFrequency(group, checkedId);
        } else if (id == R.id.rg_mainBottomFrequency) {
            //分区清扫次数
            setCleaningTimes(group, checkedId);
        } else if (id == R.id.rg_mainBottomCleanMode) {
            //zw2x清扫模式
            setCleanMode(group, checkedId);
        } else if (id == R.id.rg_BaseStation_waterLayout) {
            switchWater(group, checkedId);
        }
    }

    /**
     * 基站水量设置
     */
    private void switchWater(RadioGroup group, int checkedId) {
        View viewById = group.findViewById(checkedId);
        if (!viewById.isPressed()) {
            return;
        }
        int mopWater = 0;
        if (checkedId == R.id.iv_main_BaseStation_water01) {
            mopWater = 0;
        } else if (checkedId == R.id.iv_main_BaseStation_water02) {
            mopWater = 1;
        } else if (checkedId == R.id.iv_main_BaseStation_water03) {
            mopWater = 2;
        } else if (checkedId == R.id.iv_main_BaseStation_water04) {
            mopWater = 3;
        }

//        //禁止点击
//        mRbMainBaseStationWater01.setEnabled(false);
//        mRbMainBaseStationWater02.setEnabled(false);
//        mRbMainBaseStationWater03.setEnabled(false);
//        mRbMainBaseStationWater04.setEnabled(false);
//        if (bun_time_water == null) {
//            bun_time_water = new TimeCountWater(15000, 1000); //点击吸力水量 开始倒计时
//        }
//        bun_time_water.start();
//        if (mopWater == 0) {
//            mRlBaseStationwateBar011.setVisibility(View.VISIBLE);
//            mRlBaseStationwateBar022.setVisibility(View.GONE);
//            mRlBaseStationwateBar033.setVisibility(View.GONE);
//            mRlBaseStationwateBar044.setVisibility(View.GONE);
//
//            mRbMainBaseStationWater01.setChecked(true);
//            mRbMainBaseStationWater02.setChecked(false);
//            mRbMainBaseStationWater03.setChecked(false);
//            mRbMainBaseStationWater04.setChecked(false);
//        } else if (mopWater == 1) {
//            mRlBaseStationwateBar011.setVisibility(View.GONE);
//            mRlBaseStationwateBar022.setVisibility(View.VISIBLE);
//            mRlBaseStationwateBar033.setVisibility(View.GONE);
//            mRlBaseStationwateBar044.setVisibility(View.GONE);
//
//            mRbMainBaseStationWater01.setChecked(false);
//            mRbMainBaseStationWater02.setChecked(true);
//            mRbMainBaseStationWater03.setChecked(false);
//            mRbMainBaseStationWater04.setChecked(false);
//        } else if (mopWater == 2) {
//            mRlBaseStationwateBar011.setVisibility(View.GONE);
//            mRlBaseStationwateBar022.setVisibility(View.GONE);
//            mRlBaseStationwateBar033.setVisibility(View.VISIBLE);
//            mRlBaseStationwateBar044.setVisibility(View.GONE);
//
//            mRbMainBaseStationWater01.setChecked(false);
//            mRbMainBaseStationWater02.setChecked(false);
//            mRbMainBaseStationWater03.setChecked(true);
//            mRbMainBaseStationWater04.setChecked(false);
//        } else if (mopWater == 3) {
//            mRlBaseStationwateBar011.setVisibility(View.GONE);
//            mRlBaseStationwateBar022.setVisibility(View.GONE);
//            mRlBaseStationwateBar033.setVisibility(View.GONE);
//            mRlBaseStationwateBar044.setVisibility(View.VISIBLE);
//
//            mRbMainBaseStationWater01.setChecked(false);
//            mRbMainBaseStationWater02.setChecked(false);
//            mRbMainBaseStationWater03.setChecked(false);
//            mRbMainBaseStationWater04.setChecked(true);
//        }
        LogUtils.i("基站 : " + mopWater);
        AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().mopHumidity(mopWater).build());

    }

    private void switchingSuction(int suction) {
        //  吸力选择
        //禁止点击
        mRbMainPattern011.setEnabled(false);
        mRbMainPattern022.setEnabled(false);
        mRbMainPattern033.setEnabled(false);
        mRbMainPattern044.setEnabled(false);
        mRbMainPattern055.setEnabled(false);
        if (bun_time_sucion == null) {
            //点击吸力水量 开始倒计时
            bun_time_sucion = new TimeCountSuction(15000, 1000);
        }
        bun_time_sucion.start();

        if (suction == 0) {
            mRbPatternBar011.setVisibility(VISIBLE);
            mRbPatternBar022.setVisibility(GONE);
            mRbPatternBar033.setVisibility(GONE);
            mRbPatternBar044.setVisibility(GONE);
            mRbPatternBar055.setVisibility(GONE);

            mRbMainPattern011.setChecked(true);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 1) {
            mRbPatternBar011.setVisibility(GONE);
            mRbPatternBar022.setVisibility(VISIBLE);
            mRbPatternBar033.setVisibility(GONE);
            mRbPatternBar044.setVisibility(GONE);
            mRbPatternBar055.setVisibility(GONE);

            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(true);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 2) {
            mRbPatternBar011.setVisibility(GONE);
            mRbPatternBar022.setVisibility(GONE);
            mRbPatternBar033.setVisibility(VISIBLE);
            mRbPatternBar044.setVisibility(GONE);
            mRbPatternBar055.setVisibility(GONE);

            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(true);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 3) {
            mRbPatternBar011.setVisibility(GONE);
            mRbPatternBar022.setVisibility(GONE);
            mRbPatternBar033.setVisibility(GONE);
            mRbPatternBar044.setVisibility(VISIBLE);
            mRbPatternBar055.setVisibility(GONE);

            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(true);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 4) {
            mRbPatternBar011.setVisibility(GONE);
            mRbPatternBar022.setVisibility(GONE);
            mRbPatternBar033.setVisibility(GONE);
            mRbPatternBar044.setVisibility(GONE);
            mRbPatternBar055.setVisibility(VISIBLE);

            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(true);
        }
        LogUtils.i("下发 吸力选择: " + suction);
        AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().suction(suction).build());
    }

    /**
     * 分区清扫次数
     */
    private void setCleaningTimes(RadioGroup group, int checkedId) {
        View viewById = group.findViewById(checkedId);
        if (!viewById.isPressed()) {
            return;
        }
        if (checkedId == R.id.rb_mainBottomRoomx1) {
            robot.getSetTemporaryPara().setRoomFrequency(1);
        } else if (checkedId == R.id.rb_mainBottomRoomx2) {
            robot.getSetTemporaryPara().setRoomFrequency(2);
        }
    }

    /**
     * 设置回洗频率
     */
    private void setBackwashFrequency(RadioGroup group, int checkedId) {
        View viewById = group.findViewById(checkedId);
        if (!viewById.isPressed()) {
            return;
        }
        int frequency = 0;
        if (checkedId == R.id.iv_main_BackwashFrequency10) {
            frequency = 10;
        } else if (checkedId == R.id.iv_main_BackwashFrequency20) {
            frequency = 20;
        } else if (checkedId == R.id.iv_main_BackwashFrequency30) {
            frequency = 30;
        }
        AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().backwashFrequency(frequency).build());
    }

    private void setCleanMode(RadioGroup group, int checkedId) {
        View viewById = group.findViewById(checkedId);
        if (!viewById.isPressed()) {
            return;
        }
        int suction = 0;
        int water = 0;
        int workMode = 0;
        if (checkedId == R.id.rb_SweepDragMode) {
            suction = robot.getCleanSettings().getSuction();
            water = robot.getCleanSettings().getMopHumidity();
            workMode = 0;
            mLlMainBottomSuction.setVisibility(VISIBLE);
            mLlMainBottomBaseStationWater.setVisibility(VISIBLE);
        } else if (checkedId == R.id.rb_dragOnlyMode) {
            water = robot.getCleanSettings().getMopHumidity();
            suction = 0;
            workMode = 2;
            mLlMainBottomBaseStationWater.setVisibility(VISIBLE);
            mLlMainBottomSuction.setVisibility(GONE);
        } else if (checkedId == R.id.rb_scanOnlyMode) {
            suction = robot.getCleanSettings().getSuction();
            water = 0;
            workMode = 1;
            mLlMainBottomSuction.setVisibility(VISIBLE);
            mLlMainBottomBaseStationWater.setVisibility(GONE);
        }
        LogUtils.i("工作2x清扫模式 下发 吸力 水量 " + suction + " , " + water);
        AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().suction(suction).build());
        AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().mopHumidity(water).build());
        AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().setWorkMode(workMode).build());
    }

    /**
     * 清扫模式（zw2x）
     *
     * @param cleanMode
     */
    private void setCleanModeInitialize(int cleanMode) {
        LogUtils.i("清扫模式 " + cleanMode);
        if (0 == cleanMode) {
            //both_work - 扫拖模式
            rb_SweepDragMode.setChecked(true);
            mLlMainBottomSuction.setVisibility(VISIBLE);
            mLlMainBottomBaseStationWater.setVisibility(VISIBLE);
        } else if (1 == cleanMode) {
            //only_sweep - 只扫模式
            rb_scanOnlyMode.setChecked(true);
            mLlMainBottomSuction.setVisibility(VISIBLE);
            mLlMainBottomBaseStationWater.setVisibility(GONE);
        } else if (2 == cleanMode) {
            //only_mop - 只拖模式
            rb_dragOnlyMode.setChecked(true);
            mLlMainBottomSuction.setVisibility(GONE);
            mLlMainBottomBaseStationWater.setVisibility(VISIBLE);
        }
    }

    public void initializationData(String dynamic_static, String tag) {

        Robot device = AppContext.get().getCurrentDevice();
        LogUtils.i(dynamic_static + " : initializationData*************************** : " + tag);
        if (device == null) {
            return;
        }
        if (dynamic_static.equals("static_open") || dynamic_static.equals("static")) {
            //todo; 这里是隐藏第一个吸力 mRbMainPattern011 暂时改成 mRbMainWater01
            //根据产品显示设置的条目
            setCleanSettingLayout(device.getConfig());
            //根据状态默认选择 模式，如果底部已经打开 就不动态更新选择模式
//            Log.d(TAG, workState + " workState *************************** workMode: " + workMode);
            selectMode();
        }
    }

    private void setCleanSettingLayout(JSONObject productConfig) {
        DisplayUtil.show(mRbMainChooseRoom, productConfig.optBoolean(ProductConfigConstants.cleanSetting_chooseRoom));
        DisplayUtil.show(mRbMainSpotClean, productConfig.optBoolean(ProductConfigConstants.cleanSetting_spotClean));
        DisplayUtil.show(mRbMainSweepAlongWall, productConfig.optBoolean(ProductConfigConstants.cleanSetting_edgeClean));
        DisplayUtil.show(mRbMainQuickCleaning, productConfig.optBoolean(ProductConfigConstants.cleanSetting_quickClean));
        DisplayUtil.show(mRlMainBottomCustomMode, productConfig.optBoolean(ProductConfigConstants.cleanSetting_customMode));
        DisplayUtil.show(mRlMainBottomSterilizationMode, productConfig.optBoolean(ProductConfigConstants.cleanSetting_sterilizeMode));
        DisplayUtil.show(mRlMainBottomWipingMode, productConfig.optBoolean(ProductConfigConstants.cleanSetting_fineRub));
        DisplayUtil.show(mRlPatternOne, productConfig.optBoolean(ProductConfigConstants.cleanSetting_noneSuction));
        DisplayUtil.show(mLlMainBottomBackwashFrequency, productConfig.optBoolean(ProductConfigConstants.cleanSetting_selfCleaningFrequency));
        DisplayUtil.show(mLlMainBottomAutoBoost, productConfig.optBoolean(ProductConfigConstants.cleanSetting_carpetPressurization));
        DisplayUtil.show(mLlMainBottomBaseStationWater, productConfig.optBoolean(ProductConfigConstants.cleanSetting_mopWater));
        DisplayUtil.show(mRbMainBaseStationWater01, productConfig.optBoolean(ProductConfigConstants.cleanSetting_hasDryMop));
        DisplayUtil.show(mLlMainBottomSuction, productConfig.optBoolean(ProductConfigConstants.cleanSetting_suction));
        DisplayUtil.show(ll_mainBottomCarpetSetting, productConfig.optBoolean(ProductConfigConstants.carpetSetting_suction));
        DisplayUtil.show(ll_mainBottomCleanMode, productConfig.optBoolean(ProductConfigConstants.carpetSetting_suction));
        DisplayUtil.show(mRlPatternFour, productConfig.optBoolean(ProductConfigConstants.cleanSetting_Max_Suction_show));
    }

    public void setSuctionWater() {
        Robot device = AppContext.get().getCurrentDevice();
        if (device == null) {
            return;
        }
        //根据不同的机器型号，进行设置对应的功能显示
        JSONObject productConfig = device.getConfig();
        CleanSettings settings = device.getCleanSettings();
        mSuction = settings.getSuction();//获取吸力
        mWater = settings.getMopHumidity();//获取水量

        int frequency = settings.getBackwashFrequency(); //回洗频率
        LogUtils.i(mSuction + " suction*************************** water: " + mWater);

        if (productConfig.optBoolean(ProductConfigConstants.cleanSetting_isConbineWaterTankAndDustBox)) {
            //二合一水箱尘盒
            setSuction(mSuction);
            setWater(mWater);
            setBackWaskFrequency(frequency);
            mRbMainBaseStationWater01.setVisibility(productConfig.optBoolean(ProductConfigConstants.cleanSetting_hasDryMop) ? View.VISIBLE : View.GONE);
            mRbMainPattern011.setVisibility(productConfig.optBoolean(ProductConfigConstants.cleanSetting_noneSuction) ? View.VISIBLE : View.GONE);
        } else {
            if (productConfig.optBoolean(ProductConfigConstants.cleanSetting_OnlySuctionShown)) {
                //N5的机器只显示吸力
                mLlMainBottomSuction.setVisibility(VISIBLE);//吸力
                mLlMainBottomBaseStationWater.setVisibility(GONE);
                setSuction(mSuction);
            } else {
                if (!productConfig.optBoolean(ProductConfigConstants.carpetSetting_suction)) {
                    //除U3PRO N5外  尘盒水箱分开  x3 x3s
                    boolean tankStatus = settings.isTankStatus();//水箱状态
                    boolean dustBoxStatus = settings.isDustBoxStatus();//尘盒状态
                    LogUtils.i(tankStatus + " ：水箱状态*************************** 尘盒状态: " + dustBoxStatus);
                    if (dustBoxStatus) {
                        mLlMainBottomBaseStationWater.setVisibility(GONE);
                        mLlMainBottomSuction.setVisibility(VISIBLE);//吸力
                        setSuction(mSuction);
                    } else if (tankStatus) {
                        mLlMainBottomSuction.setVisibility(VISIBLE);//吸力
                        mLlMainBottomBaseStationWater.setVisibility(VISIBLE);
                        setSuction(mSuction);
                        setWater(mWater);
                    } else {
                        //如果没有水箱也没有尘盒
                        mLlMainBottomSuction.setVisibility(GONE);
                        mLlMainBottomBaseStationWater.setVisibility(GONE);
                    }
                } else {
                    setSuction(mSuction);
                    setWater(mWater);
                }
            }
        }
        setCcustomMode();
    }

    //设置定制模式
    public void setCcustomMode() {
        Robot device = AppContext.get().getCurrentDevice();
        if (device == null) {
            return;
        }
        //根据不同的机器型号，进行设置对应的功能显示
        JSONObject productConfig = device.getConfig();
        CleanSettings settings = device.getCleanSettings();
        boolean customSwitch = settings.isCustomSwitch();
        if (customSwitch_record != customSwitch) {
            LogUtils.i(customSwitch + " 定制模式 *************************** ");
            customSwitch_record = customSwitch;
            mCbMainCustomMade.setChecked(customSwitch);//定制模式
        }
        boolean carpetPressurize = settings.isCarpetPressurize();////地毯增压
        boolean fineBrush = settings.isFineBrush();//精擦
        if (carpetPressurize_record != carpetPressurize) {
            carpetPressurize_record = carpetPressurize;
            LogUtils.i("*************************** 地毯增压: " + carpetPressurize);
            mCbMainSupercharge.setChecked(carpetPressurize);//地毯增压
            mCbMainFineRub.setChecked(fineBrush);
        }
        if (productConfig.optBoolean(ProductConfigConstants.carpetSetting_suction)) {
            //清扫模式 （ZW2X）
            int mCleanMode = settings.getWorkMode();//清扫模式
            if (cleanMode != mCleanMode) {
                cleanMode = mCleanMode;//防止多次上报时，重复
                setCleanModeInitialize(mCleanMode);
            }
            int carpetSetting = settings.getCarpetSetting();
            if (carpetSetting == 0) {
                smartBlanket();
            } else if (carpetSetting == 1) {
                autoBlanket();
            }
        }
    }


    //TODO 这些Radiobutton 可以设置分组 选中一个其他自动false 不用这个全部设置一遍
    private void setWater(int water) {
        if (water_record == water) {
            return;
        }
        water_record = water;
        LogUtils.i(water_record + " qqqqq: setWater() jjjj : " + water);
//        water_record = water;
//        mRlBaseStationwateBar011.setVisibility(View.GONE);
//        mRlBaseStationwateBar022.setVisibility(View.GONE);
//        mRlBaseStationwateBar033.setVisibility(View.GONE);
//        mRlBaseStationwateBar044.setVisibility(View.GONE);
        if (water == 0) {
            mRbMainBaseStationWater01.setChecked(true);
//            mRbMainBaseStationWater02.setChecked(false);
//            mRbMainBaseStationWater03.setChecked(false);
//            mRbMainBaseStationWater04.setChecked(false);
        } else if (water == 1) {
//            mRbMainBaseStationWater01.setChecked(false);
            mRbMainBaseStationWater02.setChecked(true);
//            mRbMainBaseStationWater03.setChecked(false);
//            mRbMainBaseStationWater04.setChecked(false);
        } else if (water == 2) {

//            mRbMainBaseStationWater01.setChecked(false);
//            mRbMainBaseStationWater02.setChecked(false);
            mRbMainBaseStationWater03.setChecked(true);
//            mRbMainBaseStationWater04.setChecked(false);
        } else if (water == 3) {
//            mRbMainBaseStationWater01.setChecked(false);
//            mRbMainBaseStationWater02.setChecked(false);
//            mRbMainBaseStationWater03.setChecked(false);
            mRbMainBaseStationWater04.setChecked(true);
        }
//        if (bun_time_water != null) {
//            bun_time_water.cancel();//终止按钮倒计时
//        }
    }

    private void setSuction(int suction) {
        LogUtils.i("suction : " + suction);
        if (suction_record == suction) {
            return;//如果与上次的数据相同就不进行刷新
        }
        suction_record = suction;
        mRbPatternBar011.setVisibility(GONE);
        mRbPatternBar022.setVisibility(GONE);
        mRbPatternBar033.setVisibility(GONE);
        mRbPatternBar044.setVisibility(GONE);
        mRbPatternBar055.setVisibility(GONE);
        if (suction == 0) {
            mRbMainPattern011.setChecked(true);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 1) {
            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(true);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 2) {
            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(true);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 3) {
            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(true);
            mRbMainPattern055.setChecked(false);
        } else if (suction == 4) {
            mRbMainPattern011.setChecked(false);
            mRbMainPattern022.setChecked(false);
            mRbMainPattern033.setChecked(false);
            mRbMainPattern044.setChecked(false);
            mRbMainPattern055.setChecked(true);
        }
        if (bun_time_sucion != null) {
            bun_time_sucion.cancel();//终止按钮倒计时
        }
    }

    public void setBackWaskFrequency(int frequency) {
        if (frequency == 10) {
            mRbMainBackwashFrequency10.setChecked(true);
        } else if (frequency == 20) {
            mRbMainBackwashFrequency20.setChecked(true);
        } else if (frequency == 30) {
            mRbMainBackwashFrequency30.setChecked(true);
        }
    }

    /**
     * 获取分区的房间
     */
    public void roomSelect() {
        robot = AppContext.get().getCurrentDevice();
        List<Room> mapRoomList = getCopyRooms();
//        Log.d(TAG, "  roomSelect 上拉获取房间号*************************** : " + mapRoomList.size());
        if (mapRoomList.size() == 0) {
            //没有房间，默认禁止点击状态
            mRlMainBottomCustomMode.setVisibility(GONE);//定制模式
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_prohibit_icon);
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.hint_gray));
            //mRbMainChooseRoom.setClickable(false); 徐老师说改成可点击，样式不变
            mMainBottomCustomizeEdit.setVisibility(GONE);//没有房间分区，隐藏定制编辑
            mMainCleanType.setVisibility(View.GONE);
            return;
        } else {
            mRlMainBottomCustomMode.setVisibility(VISIBLE);//定制模式
            int selectMode = robot.getSetTemporaryPara().getSelectMode();//设置选择工作模式
            int roomFrequency = robot.getSetTemporaryPara().getRoomFrequency();
            if (selectMode == 2) {
                cleanModeBgShow02();
                if (roomFrequency == 1) {
                    rb_mainBottomRoomx1.setChecked(true);
                } else if (roomFrequency == 2) {
                    rb_mainBottomRoomx2.setChecked(true);
                }
            } else if (selectMode == 1) {
                cleanModeBgShow01();
            } else if (selectMode == 3) {
                cleanModeBgShow03();
            } else if (selectMode == 4) {
                cleanModeBgShow04();
            } else if (selectMode == 5) {
                cleanModeBgShow05();
            } else if (selectMode == 0) {
                cleanModeBgShow00();
            }
            mRbMainChooseRoom.setClickable(true);
            mMainBottomCustomizeEdit.setVisibility(VISIBLE);
        }
        //设备列表adapter
        mRoomAdapter.updateData(mapRoomList, mSelectdRoomIds);
    }

    private List<Room> getCopyRooms() {
        Map map = AppContext.get().getCurrentDevice().getMap();
        List<Room> room = map.getRoom();
        List<Room> copyRooms = new ArrayList<>();
        for (int i = 0; i < room.size(); i++) {
            Room roomBean = new Room();
            roomBean.setId(room.get(i).getId());
            roomBean.setName(room.get(i).getName());
            roomBean.setOrder(0);
            copyRooms.add(roomBean);
        }
        return copyRooms;
    }

    /**
     * 开始清扫按钮 ，长按事件
     *
     * @param content
     * @param type
     */
    private void showLongClickDialog(String content, int type) {
        CommonConfirmDialog2.newBuilder()
                .context(mainActivity)
                .message(content)
                .confirmCallback(new CommonConfirmDialog2.ConfirmCallback() {
                    @Override
                    public boolean onConfirm() {
                        if (type == 1) {
                            //停止清扫
                            AppContext.getProductService().stopSweep();
                        } else {
                            //停止回充
                            AppContext.getProductService().stopRecharge();
                        }
                        return true;
                    }

                    @Override
                    public boolean onCancel() {
                        return true;
                    }
                }).build().show();
    }


    /**
     * 根据状态模式，默认底部选中对应的模式
     */
    public void selectMode() {
        robot = AppContext.get().getCurrentDevice();
        if (robot == null) {
            LogUtils.i("selectMode*************************** get robot is null ");
            return;
        }
        int state = robot.getRobotStatus().getWorkState();
        int mode = robot.getRobotStatus().getWorkMode();
        LogUtils.i(state + "  selectMode*************************** : " + mode);// mainActivity.param.setType(RobotStatus.MODE_AUTO_CLEAN);
        if ((state == RobotStatus.STATE_WORKING || state == RobotStatus.STATE_PAUSE) &&
                (mode == RobotStatus.MODE_ROOM_CLEAN ||
                        mode == RobotStatus.MODE_AUTO_CLEAN ||
                        mode == RobotStatus.MODE_CUSTOM_CLEAN ||
                        mode == RobotStatus.MODE_SPOT_CLEAN ||
                        mode == RobotStatus.MODE_EDGE_CLEAN)) {
            cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
            //如果是工作中或暂停的状态就全不选中
            mStateMode = "";
            robot.getSetTemporaryPara().setSelectMode(0);
            cleanModeBgShow00();
        } else if (state == RobotStatus.STATE_WORKING && mode == RobotStatus.MODE_RECHARGE) {
//            Log.d(TAG, "  selectMode*************************** :回充中 ");
            //全局清扫
            if (mStateMode.equals("")) {
                cleanModeBgShow01();
                robot.getSetTemporaryPara().setSelectMode(1);
                mStateMode = "";
                cleanModeCheck01();
            } else {
                //当有手动选中模式时，此时有状态上来就不更新选择模式，但要设置所有的模式按钮可以点击
                cleanModeCheck00();
            }
//            Log.d(TAG, "  selectMode*************************** :www " + mStateMode);
        } else if (state == RobotStatus.STATE_PAUSE && mode == RobotStatus.MODE_RECHARGE) {
            if (mStateMode.equals("")) {
                //如果是工作中或暂停的状态就全不选中
                robot.getSetTemporaryPara().setSelectMode(0);
                cleanModeBgShow00();
            } else {
                //当有手动选中模式时，此时有状态上来就不更新选择模式，但要设置所有的模式按钮可以点击
                cleanModeCheck00();
            }
        } else {
            LogUtils.i("  selectMode*************************** :hhhh " + mStateMode);
            if (mStateMode.equals("")) {
                cleanModeParam.setType(RobotStatus.MODE_AUTO_CLEAN);
                //全局清扫
                robot.getSetTemporaryPara().setSelectMode(1);
                cleanModeBgShow01();
                cleanModeCheck01();
            } else {
                //当有手动选中模式时，此时有状态上来就不更新选择模式，但要设置所有的模式按钮可以点击
                cleanModeCheck00();
            }

        }
    }

    private void cleanModeBgShow00() {
        LogUtils.i("  cleanModeBgShow00*************************** : ");
        mRbMainHouseClean.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainHouseClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        List<Room> room = AppContext.get().getCurrentDevice().getMap().getRoom();
        if (room.size() > 0) {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
            mRbMainChooseRoom.setClickable(true);
        } else {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_prohibit_icon);
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.hint_gray));
            // mRbMainChooseRoom.setClickable(false);徐老师说改成可点击，样式不变
        }
        mRbMainSpotClean.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSpotClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainSweepAlongWall.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSweepAlongWall.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainQuickCleaning.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainQuickCleaning.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainHouseClean.setClickable(true);
        mRbMainChooseRoom.setClickable(true);
        mRbMainSpotClean.setClickable(true);
        mRbMainSweepAlongWall.setClickable(true);
        mRbMainQuickCleaning.setClickable(true);
        mMainCleanType.setVisibility(View.GONE);
        //如果选择了其他的模式就把之前选择的数据给清除掉

    }

    private void cleanModeBgShow01() {
        mRbMainHouseClean.setBackgroundResource(R.mipmap.button_bg_selector_icon);//选中
        mRbMainHouseClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.background_color));
        List<Room> room = AppContext.get().getCurrentDevice().getMap().getRoom();
        LogUtils.i("  cleanModeBgShow01*************************** : " + room.size());
        if (room.size() > 0) {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
            mRbMainChooseRoom.setClickable(true);
        } else {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_prohibit_icon);
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.hint_gray));
            // mRbMainChooseRoom.setClickable(false);徐老师说改成可点击， 样式不变
        }
        mRbMainSpotClean.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSpotClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainSweepAlongWall.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSweepAlongWall.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainQuickCleaning.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainQuickCleaning.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mMainCleanType.setVisibility(View.GONE);
    }

    private void cleanModeBgShow02() {

        mMainCleanType.setVisibility(View.VISIBLE);

        mRbMainHouseClean.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
        mRbMainHouseClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainChooseRoom.setBackground(getResources().getDrawable(R.mipmap.button_bg_selector_icon));//选中
        mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.background_color));
        mRbMainSpotClean.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSpotClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainSweepAlongWall.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSweepAlongWall.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainQuickCleaning.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainQuickCleaning.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        LogUtils.i("  cleanModeBgShow02*************************** : ");
    }

    private void cleanModeBgShow03() {
        LogUtils.i("局部清扫 cleanModeBgShow03");
        mRbMainHouseClean.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
        mRbMainHouseClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        List<Room> room = AppContext.get().getCurrentDevice().getMap().getRoom();
        if (room.size() > 0) {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
            mRbMainChooseRoom.setClickable(true);
        } else {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_prohibit_icon);
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.hint_gray));
            // mRbMainChooseRoom.setClickable(false);徐老师说改成可点击， 样式不变
        }
        mRbMainSpotClean.setBackgroundResource(R.mipmap.button_bg_selector_icon);//选中
        mRbMainSpotClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.background_color));
        mRbMainSweepAlongWall.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSweepAlongWall.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainQuickCleaning.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainQuickCleaning.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mMainCleanType.setVisibility(View.GONE);
    }

    private void cleanModeBgShow04() {
        mRbMainHouseClean.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
        mRbMainHouseClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        List<Room> room = AppContext.get().getCurrentDevice().getMap().getRoom();
        if (room.size() > 0) {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
            mRbMainChooseRoom.setClickable(true);
        } else {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_prohibit_icon);
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.hint_gray));
            // mRbMainChooseRoom.setClickable(false);徐老师说改成可点击， 样式不变
        }
        mRbMainSpotClean.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSpotClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainSweepAlongWall.setBackgroundResource(R.mipmap.button_bg_selector_icon);//选中
        mRbMainSweepAlongWall.setTextColor(ContextCompat.getColor(mainActivity, R.color.background_color));
        mRbMainQuickCleaning.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainQuickCleaning.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mMainCleanType.setVisibility(View.GONE);
    }

    private void cleanModeBgShow05() {
        mRbMainHouseClean.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
        mRbMainHouseClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        List<Room> room = AppContext.get().getCurrentDevice().getMap().getRoom();
        if (room.size() > 0) {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_icon);//未选中
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
            mRbMainChooseRoom.setClickable(true);
        } else {
            mRbMainChooseRoom.setBackgroundResource(R.mipmap.button_bg_default_prohibit_icon);
            mRbMainChooseRoom.setTextColor(ContextCompat.getColor(mainActivity, R.color.hint_gray));
            //mRbMainChooseRoom.setClickable(false);徐老师说改成可点击， 样式不变
        }
        mRbMainSpotClean.setBackgroundResource(R.mipmap.button_bg_default_icon);
        mRbMainSpotClean.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainSweepAlongWall.setBackgroundResource(R.mipmap.button_bg_default_icon);//选中
        mRbMainSweepAlongWall.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        mRbMainQuickCleaning.setBackgroundResource(R.mipmap.button_bg_selector_icon);//选中
        mRbMainQuickCleaning.setTextColor(ContextCompat.getColor(mainActivity, R.color.background_color));
        mMainCleanType.setVisibility(View.GONE);
    }

    private void cleanModeCheck00() {
        LogUtils.i("  selectMode***************************cleanModeCheck00 : ");
        mRbMainHouseClean.setClickable(true);
        mRbMainChooseRoom.setClickable(true);
        mRbMainSpotClean.setClickable(true);
        mRbMainSweepAlongWall.setClickable(true);
        mRbMainQuickCleaning.setClickable(true);
    }

    private void cleanModeCheck01() {
        LogUtils.i("  selectMode***************************cleanModeCheck01 : ");
        mRbMainHouseClean.setClickable(false);
        mRbMainChooseRoom.setClickable(true);
        mRbMainSpotClean.setClickable(true);
        mRbMainSweepAlongWall.setClickable(true);
        mRbMainQuickCleaning.setClickable(true);
    }

    private void cleanModeCheck02() {
        mRbMainHouseClean.setClickable(true);
        mRbMainChooseRoom.setClickable(true);//徐老师说改成可点击， 样式不变
        mRbMainSpotClean.setClickable(true);
        mRbMainSweepAlongWall.setClickable(true);
        mRbMainQuickCleaning.setClickable(true);
    }

    private void cleanModeCheck03() {
        //局部
        mRbMainHouseClean.setClickable(true);
        mRbMainChooseRoom.setClickable(true);
        mRbMainSpotClean.setClickable(false);
        mRbMainSweepAlongWall.setClickable(true);
        mRbMainQuickCleaning.setClickable(true);
    }

    private void cleanModeCheck04() {
        //沿墙
        mRbMainHouseClean.setClickable(true);
        mRbMainChooseRoom.setClickable(true);
        mRbMainSpotClean.setClickable(true);
        mRbMainSweepAlongWall.setClickable(false);
        mRbMainQuickCleaning.setClickable(true);
    }

    private void cleanModeCheck05() {
        //快速
        mRbMainHouseClean.setClickable(true);
        mRbMainChooseRoom.setClickable(true);
        mRbMainSpotClean.setClickable(true);
        mRbMainSweepAlongWall.setClickable(true);
        mRbMainQuickCleaning.setClickable(false);
    }

    private void clearSelectRoom() {
        //Constants.roomFrequency = 1;
        robot.getSetTemporaryPara().setRoomFrequency(1);
        rb_mainBottomRoomx1.setChecked(true);
        List<Room> mapRoom = getCopyRooms();
        mRoomAdapter.updateData(mapRoom, mSelectdRoomIds);
    }

    /**
     * 恢复吸力 水量 按钮状态
     */
    public void recoverWaterBtn() {
        LogUtils.i(" : ++++++++++++++++水量+++++++++++++++++++ : 恢复吸力 水量 按钮状态");
        if (mRlBaseStationwateBar011 != null) {
            mRlBaseStationwateBar011.setVisibility(View.GONE);
            mRlBaseStationwateBar022.setVisibility(View.GONE);
            mRlBaseStationwateBar033.setVisibility(View.GONE);
            mRlBaseStationwateBar044.setVisibility(View.GONE);

            mRbMainBaseStationWater01.setEnabled(true);
            mRbMainBaseStationWater02.setEnabled(true);
            mRbMainBaseStationWater03.setEnabled(true);
            mRbMainBaseStationWater04.setEnabled(true);
        }
    }

    /**
     * 恢复吸力 水量 按钮状态
     */
    public void recoverSuctionBtn() {
        //吸力转圈圈关闭
        if (mRbPatternBar011 != null) {
            mRbPatternBar011.setVisibility(View.GONE);
            mRbPatternBar022.setVisibility(View.GONE);
            mRbPatternBar033.setVisibility(View.GONE);
            mRbPatternBar044.setVisibility(View.GONE);
            mRbPatternBar055.setVisibility(View.GONE);

            //解禁点击
            mRbMainPattern011.setEnabled(true);
            mRbMainPattern022.setEnabled(true);
            mRbMainPattern033.setEnabled(true);
            mRbMainPattern044.setEnabled(true);
            mRbMainPattern055.setEnabled(true);
        }

    }

    private void smartBlanket() {
        tv_mainBottomSmartBlanket1.setTextColor(ContextCompat.getColor(mainActivity, R.color.white));
        tv_mainBottomSmartBlanket2.setTextColor(ContextCompat.getColor(mainActivity, R.color.background_color));
        tv_mainBottomAutoBlanket1.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        tv_mainBottomAutoBlanket2.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color3));
        ll_mainBottomSmartBlanket.setBackgroundResource(R.mipmap.button_bg_selector_icon);//选中
        ll_mainBottomAutoBlanket.setBackgroundResource(R.mipmap.button_bg_default_icon);
    }

    private void autoBlanket() {
        tv_mainBottomSmartBlanket1.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color2));
        tv_mainBottomSmartBlanket2.setTextColor(ContextCompat.getColor(mainActivity, R.color.textview_color3));
        tv_mainBottomAutoBlanket1.setTextColor(ContextCompat.getColor(mainActivity, R.color.white));
        tv_mainBottomAutoBlanket2.setTextColor(ContextCompat.getColor(mainActivity, R.color.background_color));
        ll_mainBottomSmartBlanket.setBackgroundResource(R.mipmap.button_bg_default_icon);
        ll_mainBottomAutoBlanket.setBackgroundResource(R.mipmap.button_bg_selector_icon);//选中
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
//        Log.i(TAG, "onInterceptTouchEvent -------------------" + ev.getY());
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
//            Constants.click_location = true;//标记滑动的开始位置
            mainActivity.mainFragment.mGestureDetector.onTouchEvent(ev);
        }
        return super.onInterceptTouchEvent(ev);
    }

    /**
     * 用于点击 水量后等待指令返回
     */
    public class TimeCountWater extends CountDownTimer {

        public TimeCountWater(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            LogUtils.i("onTick-------TimeCount-------------- ");
        }

        @Override
        public void onFinish() {
            LogUtils.i("onFinish-------onFinish-------------- ");
            ToastUtil.show(mainActivity, getResources().getString(R.string.U_T_SetNo), Toast.LENGTH_LONG);
            recoverWaterBtn();
            //recoverSuctionBtn();
            setSuctionWater();
        }
    }

    /**
     * 用于点击吸力 后等待指令返回
     */
    public class TimeCountSuction extends CountDownTimer {

        public TimeCountSuction(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            LogUtils.i("onTick-------TimeCount-------------- ");
        }

        @Override
        public void onFinish() {
            LogUtils.i("onFinish-------onFinish-------------- ");
            ToastUtil.show(mainActivity, getResources().getString(R.string.U_T_SetNo), Toast.LENGTH_LONG);
//            recoverWaterBtn();
            recoverSuctionBtn();
            setSuctionWater();
        }
    }

    /**
     * 用于点击切换模式后等待指令返回
     */
    public class TimeCountMode extends CountDownTimer {

        public TimeCountMode(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            LogUtils.i("onTick-------TimeCount Mode-------------- ");
        }

        @Override
        public void onFinish() {
            Constants.bun_time_mode = false;
        }
    }

}
